package com.yc.pay.service.impl;

import com.yc.pay.mapper.PayNoticeMapper;
import com.yc.pay.model.PayNotice;
import com.yc.pay.service.IPayNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;

@Service
public class PayNoticeServiceImpl implements IPayNoticeService {

    @Autowired
    private PayNoticeMapper payNoticeMapper;

    @Override
    public void createPayNotice(String paySerialNo,String status){

        PayNotice payNotice =  payNoticeMapper.queryBySerialNo(paySerialNo);
        PayNotice record = new PayNotice();
        Date date = new Date();
        if (ObjectUtils.isEmpty(payNotice)){
            record.setNoticeCount(1);
            record.setStatus(status);
            record.setUpdateTime(date);
            record.setNoticeTime(date);
            record.setPaySerialNo(paySerialNo);
            payNoticeMapper.insert(record);
            return;
        }

        //更新
        record.setId(payNotice.getId());
        record.setStatus(status);
        record.setNoticeCount(payNotice.getNoticeCount() + 1);
        record.setNoticeTime(date);
        payNoticeMapper.updateByPrimaryKeySelective(record);


    }

    @Override
    public void upatePayNotice(String paySerialNo,String status) {

    }

    @Override
    public PayNotice queryPayNotieByPaySerialNo(String paySerial) {
        return null;
    }
}
